//////////////////////////////////////////////////////////////////////////////////////////
// NAME: BlockUnblockPopup.java								           					//
// AUTHOR: CDT Peter Lofreddo															//
// LAST MODIFIED: 22 February 2012														//
// DESCRIPTION: Opens popup to block,unblock, or uninstall a program 					//
// LIMITATIONS: 																		//
// CITATIONS: Inside Individual Methods.												//
//																						//
////////////////////////////////////////////////////////////////////////////////////////// 
package prototype.revision;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.widget.Toast;

public class BlockUnblockPopup {
	String TAG = "PopUpActivity";
	private Activity act;
	private FileOperations fop;
	private Blocker blkr;
	private GeneralSettings statusBar = new GeneralSettings();
	int i;

	public BlockUnblockPopup(ListViewActivity activity, FileOperations fo) {
		// TODO Auto-generated constructor stub
		act = activity;
		fop = fo;
		blkr = new Blocker(fop);
		Log.i(TAG, "Constructing object...");
	}

	public void clearBlackListorWhiteList(){
		// Items you would like to list as options.
		final String black = "Black List";
		final String white = "White List";
		final CharSequence[] items = { black, white};
		AlertDialog.Builder builder = new AlertDialog.Builder(act);

		// Title of Popup
		builder.setTitle("What list do you want to reset?");
		builder.setSingleChoiceItems(items, -1,
				new DialogInterface.OnClickListener() {
					// When you click the radio button
					public void onClick(DialogInterface dialog, int item) {
						i = item;
					}
				});
		// When you click Confirm
		builder.setPositiveButton("Confirm",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int item) {

						if (items[i] == black) {
							if (statusBar.getStatusBarBool() == true){
								fop.ClearFile("black.txt");
							//statusBar.statusNotificationClearFile("File Reset", "The " + black + " has been cleared!", black, act); 
							}
						}
						if (items[i] == white) {
							if (statusBar.getStatusBarBool() == true){
								fop.ClearFile("white.txt");
							//	statusBar.statusNotificationClearFile("File Reset", "The " + white + " has been cleared!", white, act);
							}
						}
					}
				});
		// When you click Cancel, Leaves PopUp.
		builder.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
					}
				});
		// Creates the AlertDialog
		AlertDialog alert = builder.create();
		// Starts the Popup.
		alert.show();
	}
	
	public void BlockUnblockUninstallPopUp(final String PackageName) {
		// ////////////////////////////////////////////////////////////////////////////////////////
		// NAME: BlockUnblockUninstallPopUp(String PackageName)
		// AUTHOR: CDT Peter Lofreddo
		// LAST MODIFIED: 22 February 2012
		// DESCRIPTION: Opens a Popup which will Block, Unblock or Uninstall
		// that application
		// CITATIONS: Adapted From http://android-codes-examples.blogspot.com/
		// 2011/03/how-to-display-alertdialog-and.html
		//
		// ////////////////////////////////////////////////////////////////////////////////////////

		// Items you would like to list as options.
		final CharSequence[] items = { "Block", "UnBlock", "Uninstall" };
		AlertDialog.Builder builder = new AlertDialog.Builder(act);

		// Title of Popup
		builder.setTitle("What would you like to do for " + PackageName + "?");
		builder.setSingleChoiceItems(items, -1,
				new DialogInterface.OnClickListener() {
					// When you click the radio button
					public void onClick(DialogInterface dialog, int item) {
						i = item;
					}
				});
		// When you click Confirm
		builder.setPositiveButton("Confirm",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int item) {
						String title = "Application";
						String app = PackageName;
						String status = "ed";

						if (items[i] == "Block") {
							Toast.makeText(act, PackageName + " Blocked.",
									Toast.LENGTH_SHORT).show();
							blkr.block(PackageName);
							if (statusBar.getStatusBarBool() == true){
							//statusBar.statusNotificationBlocker(title + " Blocked", app, "Block"+status, act); 
							}
							Log.d(TAG, PackageName + " Blocked.");
						}
						if (items[i] == "UnBlock") {
							Toast.makeText(act, PackageName + " UnBlocked.",
									Toast.LENGTH_LONG).show();
							if (statusBar.getStatusBarBool() == true){
							//	statusBar.statusNotificationBlocker(title + " Unblocked", app, "Unblock"+status, act); 
							}
							blkr.unBlock(PackageName);
							Log.d(TAG, PackageName + " Unblocked.");
						}
						if (items[i] == "Uninstall") {
							fop.UninstallApplication(PackageName);
							fop.RemoveStrFromFile("installed_programs.txt", PackageName);
							if (statusBar.getStatusBarBool() == true){
							//	statusBar.statusNotificationBlocker(title + " Uninstalled", app, "Uninstall"+status, act); ;

							}
							Log.d(TAG, PackageName + " Uninstalled.");
						}
					}
				});
		// When you click Cancel, Leaves PopUp.
		builder.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
					}
				});
		// Creates the AlertDialog
		AlertDialog alert = builder.create();
		// Starts the Popup.
		alert.show();
	}

	
}
